<template>
  <div :class="className" :style="{height:height,width:width}"></div>
</template>

<script>
import * as echarts from 'echarts';

require('echarts/theme/macarons') // echarts theme
import resize from './mixins/resize'

export default {
  mixins: [resize],
  name: "Dashboard",
  props: {
    className: {
      type: String,
      default: 'chart'
    },
    width: {
      type: String,
      default: '100%'
    },
    height: {
      type: String,
      default: '300px'
    },
    backgroundColor: {
      type: String,
      default:'#375A88'
    }
  },
  data() {
    return {
      chart: null
    }
  },
  mounted() {
    this.$nextTick(() => {
      this.initChart()
    })
  },
  beforeDestroy() {
    if (!this.chart) {
      return
    }
    this.chart.dispose()
    this.chart = null
  },
  methods: {
    initChart() {
      this.chart = echarts.init(this.$el, 'dark')
      this.chart.setOption({
        backgroundColor:this.backgroundColor,
        title: {
          text: '辐照实验全年计划',
          left:'center',
          bottom:0
        },
        tooltip: {
          trigger: 'axis',
          axisPointer: {
            type: 'shadow'
          }
        },
        legend: {},
        grid: {
          left: '3%',
          right: '4%',
          bottom: '30',
          containLabel: true
        },
        xAxis: {
          type: 'value',
          boundaryGap: [0, 0]
        },
        yAxis: {
          type: 'category',
          data: ['计划入堆', '准备入堆', '完成入堆','准备出堆', '已出堆']
        },
        series: [
          {
            name: '',
            type: 'bar',
            data: [100,70,30,120,60],
            itemStyle: {
              normal: {
                //这里是颜色
                color: function(params) {
                  //注意，如果颜色太少的话，后面颜色不会自动循环，最好多定义几个颜色
                  var colorList = ['#4668a5','#a54671',"#89A7F8", "#595EE4", "#4576E9", "#FC9C62", "#7BC071"];
                  return colorList[params.dataIndex]
                }
              }
            }
          },

        ]
      })
    }
  }
}
</script>

